/*!
    \copyright  Copyright (c) 2023 - 2025 Qualcomm Technologies International, Ltd.
                All Rights Reserved.
                Qualcomm Technologies International, Ltd. Confidential and Proprietary.
    \file
    \addtogroup mirror_profile
    @{
    \brief      The interface implementation for background unicast handler for Mirror Profile
*/

#ifndef MIRROR_PROFILE_UNICAST_BACKGROUND_HANDLER_H_
#define MIRROR_PROFILE_UNICAST_BACKGROUND_HANDLER_H_

#include "mirror_profile_typedef.h"
#include "mirror_profile_private.h"

#ifdef ENABLE_LE_MULTIPOINT_BACKGROUND_CIS_SUPPORT

/* Time to wait before retrying sending background unicast config to secondary */
#define MIRROR_PROFILE_SEND_BACKGROUND_CONFIG_DELAY   (500)

/* Time to wait before trying to setup the background unicast session */
#define MIRROR_PROFILE_SETUP_BACKGROUND_STREAMS_DELAY (750)

/*! \brief Initializes the Mirror Profile Background Unicast Handler

    \return None.
*/
void MirrorProfile_BackgroundUnicastHandlerInit(void);

/*! \brief Function that either switches the foregroud unicast session to background OR background unicast session
           to foreground in secondary earbud. This function must be called only in secondary earbud.

    \return None.
*/
void MirrorProfile_HandleUnicastTransitionReq(const mirror_profile_lea_unicast_transition_req_t *req);

/*! \brief This function handles the unicast audio config received from primary for a background unicast session. This function
           must be called only in earbud that has a secondary role.

     \param config   The audio config information received from primary.

     \return none
*/
void MirrorProfile_HandleBackgroundLeaUnicastConfig(const mirror_profile_lea_unicast_audio_conf_req_t *audio_config);

/*! \brief This function inspects received CIS related Isoc Messages/Mirror MDM CIS messages belongs to a background unicast session
           or not.

     \param id           Message Identifier.
     \param message      Message payload for the identifier.

     \return TRUE if the message is for the background unicast session and is consumed by the Background unicast handler
             else returns FALSE.
*/
bool MirrorProfile_BackgroundUnicastMessageHandler(MessageId id, Message message);

/*! \brief This function helps to send the background audio config to secondary provided all the configs and isoc streams are ready.
           Typically used from the primary earbud to re-establish background session. For e.g when secondary goes in case
           and comes out-of case.

    \return none
*/
void MirrorProfile_SendBackgroundAudioConfig(void);

/*! \brief This function helps to setup the background unicast streams provided all the configs and isoc streams are ready.
           Typically used from the primary earbud to re-establish background session. For e.g when secondary goes in case
           and comes out-of case.

    \return none
*/
void MirrorProfile_SetupBackgroundUnicastStream(void);

/*! \brief Function that handles the handover of background unicast streams if any maintained behind.

    \return none
*/
void MirrorProfile_HandleHandoverForBackgroundUnicast(bool is_primary, const tp_bdaddr *tp_bd_addr, gatt_cid_t cid);

/*! \brief Function that helps to clear the received audio config for the background unicast session.

    \return none
*/
void MirrorProfile_ClearBackgroundLeaUnicastConfig(const mirror_profile_lea_unicast_audio_clear_req_t *ind);

/*! \brief Function that moves the unicast source to foreground.

    \param source Generic source which needs to be moved to foreground.

    \return TRUE if source is moved to foreground, otherwise FALSE.
*/
bool MirrorProfile_MoveUnicastSourceToForeground(generic_source_t source);

/*! \brief Function that moves the Foreground unicast source to Background in secondary.
*/
void MirrorProfile_MoveUnicastSourceToBackgroundInSecondary(void);

/*! \brief Checks if an unicast audio/voice source is present in the background.

    \param src   The Unicast Audio/voice source that needs to be verified

    \return TRUE if the source is present in the background, FALSE otherwise
*/
generic_source_t MirrorProfile_GetGenericLeSourceIfPresentInBackground(device_t device);

/*! \brief Checks if an unicast audio/voice source is present in the background.

    \param src   The Unicast Audio/voice source that needs to be verified

    \return TRUE if the source is present in the background, FALSE otherwise
*/
bool MirrorProfile_IsUnicastSourcePresentInBackground(generic_source_t src);

/*! \brief Clears the config sent flag for all the background source */
void MirrorProfile_ClearConfigSentForAllBackgroundSessions(void);

/*! \brief Sets the config sent flag for all the valid background source_routed

    \return TRUE if background config sent is set, FALSE otherwise.
*/
bool MirrorProfile_SetBackgroundConfigSent(void);

/*! \brief Check if any background session in a transient state(setting up/tearing down)

    \return TRUE if background session is in a transient condition FALSE othewise
*/
bool MirrorProfile_IsAnyBackgroundSessionInTransientState(void);

/*! \brief Copy ISO streams if they are already established for the unicast session in background

    \param lea_unicast the unicast config for which the iso streams needs to be copied

    \return TRUE if success, FALSE othewise
*/
bool MirrorProfile_MergeCisInfoFromBgOnSecondary(mirror_profile_lea_unicast_t *lea_unicast);

/*! \brief Get the next Mirror Profile state for the unicast session 

    \return The next mirror profile state
*/
mirror_profile_state_t  MirrorProfile_EvaluateMirrorProfileStateForUnicastSession(void);

#else /* ENABLE_LE_MULTIPOINT_BACKGROUND_CIS_SUPPORT */

#define MirrorProfile_BackgroundUnicastMessageHandler(id, message)  (FALSE)

#define MirrorProfile_ClearConfigSentForAllBackgroundSessions()

#define MirrorProfile_SetBackgroundConfigSent()  (FALSE)

#define MirrorProfile_IsAnyBackgroundSessionInTransientState() (FALSE)

#define MirrorProfile_EvaluateMirrorProfileStateForUnicastSession() MIRROR_PROFILE_STATE_CIS_CONNECTING

#define MirrorProfile_MoveUnicastSourceToBackgroundInSecondary()

#endif /* ENABLE_LE_MULTIPOINT_BACKGROUND_CIS_SUPPORT */

#endif /* MIRROR_PROFILE_UNICAST_BACKGROUND_HANDLER_H_ */
/*! @} */

